package com.fdq.bigevent.controller;

import com.fdq.bigevent.pojo.Result;
import com.fdq.bigevent.util.AliOss;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class FileController {
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        String filename = UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));
        //file.transferTo(new File("D:\\Apage2\\IdeaProjects\\big-event\\src\\main\\resources\\picture\\"+filename));
        String url = AliOss.upload(filename, file);
        return Result.success(url);
    }
}
